package paihang;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;

import option.Time;
public  class Rank {

	static String driverClass = "com.mysql.cj.jdbc.Driver"; // 驱动类的名称
	// 协议:子协议://主机名或ip地址:端口号/数据库名称
	static	String url = "jdbc:mysql://localhost:3306/saolei?serverTimezone=GMT%2B8";
	static	String username = "root";
	static	String password = "root";
	static	Connection con = null;
	static	PreparedStatement ps = null;
	static	ResultSet rs = null;

	public static void luru() {
		int row;
		try {

			Class.forName(driverClass);
			con = DriverManager.getConnection(url, username, password);
			String sql = "insert into paiming values(?)";
			ps = con.prepareStatement(sql);
			DecimalFormat    df   = new DecimalFormat("######0.00");
			ps.setDouble(1, Time.time);
			row = ps.executeUpdate();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				if (null != rs)
					rs.close();
				if (null != ps)
					ps.close();
				if (null != con)
					con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

	}
	public static ResultSet search() {

		try {

			Class.forName(driverClass);
			con = DriverManager.getConnection(url, username, password);

			// 3. 指定要执行的sql语句
			String sql = "select * from paiming order by shijian asc";
			ps = con.prepareStatement(sql);
			rs = ps.executeQuery();

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return rs;

	}

}
